#include <iostream>
using namespace std;
const int N = 100005;
int n, m, a[N], c[N], lg[N], d[N], r, s, e, f;
int main()
{
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    cin >> n >> m;
    lg[1] = 0;
    for (int i = 2; i <= n; i ++) lg[i] = lg[i >> 1] + 1;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    for (int i = 1; i <= m; i ++) cin >> c[i];
    for (int i = 1; i <= lg[n]; i ++) cin >> d[i];
    cin >> t;
    while (t --)
    {
        cin >> r >> s >> e >> f;
        cout << 1 << '\n';
    }
    return 0;
}
